let global = {
    url:'http://tfngw.tfnhg.com'
};
function setFontSize(doc, win) {
    var docEl = doc.documentElement
    var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
    var reCaculate = function () {
        var clientWidth = docEl.clientWidth
        if (!clientWidth) return
        docEl.style.fontSize = 50 * (clientWidth / 750) + 'px'
    }
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, reCaculate, false)
    doc.addEventListener('DOMContentLoaded', reCaculate, false)
}
setFontSize(document,window);

function browserRedirect() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
        //电脑端
    }else{
        //手机端
        window.location.href='mobile';
    }
}

$().ready(function(){

    sendAjaxAsync(global.url+'/Api/New/get_web',function(res){
        global.web_name = res.web_name;
        global.web_copyright = res.web_copyright;
        global.erweima = res.code;
        global.address = res.address;
        global.email = res.email;
        global.web_record = res.web_record;
        global.logo = res.logo;
        global.indexLogo = res.logo_index;
        // console.log(global.erweima);
        global.tele = res.phone;
        document.getElementsByTagName("title")[0].innerText = global.web_name;
        setNewEle('meta','keywords',res.web_keywords);
        setNewEle('meta','description',res.web_description);
    });


})

function setNewEle(ele,name,content){
    let element = document.createElement(ele);
    element.name = name;
    element.content = content;
    document.getElementsByTagName('head')[0].appendChild(element);
}


//ajax封装
function  getAjax(url,callback,data) {
    $.ajax({
        url:global.url+url,
        dataType:'json',
        data:data,
        header: {
            'content-type': 'application/json' //默认值
        },
        traditional:true,
        success:function(res){
            callback(res)
        }
    })
}
function sendAjaxAsync(url,callback,data){
    $.ajax({
        url:url,
        data:data,
        dataType:"json",
        async:false,
        success:function (res) {
            callback(res)
        }
    })
}
function postAjax(url,callback,data) {
    $.ajax({
        url:url,
        dataType:'json',
        type: 'post',
        data:data,
        header: {
            'content-type': 'application/json' //默认值
        },
        traditional:true,
        success:function(res){
            callback(res)
        }
    })
}

//获取url 参数
function getSearch(var_name){
    let query = window.location.search.substring(1);
    let vars = query.split('&');
    for(let i in vars){
        let pair = vars[i].split('=');
        if(pair[0] == var_name){
            return pair[1];
        }
    }
    return false
}


